<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 把多重内容罗列出来供你选择 
        // 每个形式 都可以添加 获取 删除   

        // 策略模式 又叫组合模式   

        // 核心 需要一个数据结构 把所有的策略(电商中叫折扣)都放到这个数据结构中
        const calprice = (function(){
                const callist = {
                '80%': function (price) {
                    return (price * 0.8).toFixed(2)
                },
                '70%': function (price) {
                    return (price * 0.7).toFixed(2)
                },
                '200-20':function (price) {
                    return price-parent(price/200)*20;
                } ,
                
            }

            function calculate(total, type) {
                if(!callist[type]){
                    return total
                }
                return callist[type](total)
            }

            // 把calculate当做一个对象来用 
            calculate.add = function (type,fn) {
                callist[type] = fn
            }

            calculate.remove = function () {
                delete callist[type]
            }

            calculate.get = function () {
                return callist
            }
            return calculate
        })()
            
       const res =  calprice(1000,'1000-500');
       console.log(res);


       const res1 =  calprice(1000,'80%');
       console.log(res1);


       calprice.add('1000-500',price => price-parseInt(price/1000)*500);
       const res2 =  calprice(3600,'1000-500');
       console.log(res2);


       console.log(calprice.get())
    </script>
</body>
</html>